from os import environ
environ.setdefault('DJANGO_SETTINGS_MODULE', 'duetopia.register.settings')
import sys
from django.db.transaction import commit_on_success
from duetopia.register.models import DataFormat, DataSource

uri = sys.argv[1]

format = DataFormat.objects.get(mimetype = 'application/vnd.ogc.se_xml')
@commit_on_success
def mksource(uri):
	return DataSource.objects.get_or_create(uri=uri, format=format)

try:
    ds, status = mksource(uri)
    print ds.format.mimetype
    print 'GOOD', uri

except:
	print 'ERROR', uri
